Skip to content

feat: MCP server — agents can search and reuse session history across tools#6

Merged
aytzey merged 3 commits into
mainfrom
feat/mcp-server
Jul 9, 2026
Merged

feat: MCP server — agents can search and reuse session history across tools#6
aytzey merged 3 commits into
mainfrom
feat/mcp-server

Conversation

@aytzey

@aytzey aytzey commented Jul 9, 2026

Copy link
Copy Markdown
Owner

What

showagent mcp — a stdio MCP server so any MCP-capable agent (Claude Code, Codex, ...) can search every past coding session on the machine, across all supported agents, and pull one in as context or convert it to continue there.

Built on the official MCP Go SDK (github.com/modelcontextprotocol/go-sdk v1.6.1) — the one new dependency.

Tools

Tool Does
list_sessions provider / workspace-substring / free-text filters (workspace + first/last user message), newest first, limit default 25 / max 100, returns pre-limit total
get_transcript user/assistant turns; max_turns keeps the most recent N (default 50) with total_turns/truncated markers
branch_session fork via session.Branch; returns new id + file + resume command
convert_session rewrite via session.Convert; returns new id + file + resume command
resume_command exact shell command + cwd, returned as a string — never executed

No delete tool by design — destructive actions stay behind the TUI's two-press confirm. Branch/convert only ever write new files through the existing atomic paths.

Testing

  • In-memory MCP client against the real server: filter/search, end-truncation, branch, convert, unknown-id/provider tool errors, and a test pinning that no delete tool is exposed. Hermetic via the provider home env overrides.
  • Live smoke test over raw stdio JSON-RPC against demo/fixtures/gen.sh fixtures: initialize → tools/list → list_sessions {"query":"rate limit"}resume_command latest, all sane.
  • gofmt / go vet / golangci-lint clean, go test ./... -race green, CGO-free cross-compile for linux/darwin/windows amd64.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added MCP support to showagent, including a new command to expose session history through agent-friendly tools.
    • Introduced tools to list sessions, view transcripts, branch sessions, convert sessions, and retrieve resume commands.
  • Documentation

    • Updated the README with MCP setup instructions, example agent configurations, tool descriptions, and safety notes.
  • Bug Fixes

    • Help output and command handling now correctly include the new MCP command.
    • Added coverage for argument validation and MCP behavior to improve reliability.

aytzey and others added 3 commits July 9, 2026 22:50
New internal/mcpserver package built on the official MCP Go SDK
(github.com/modelcontextprotocol/go-sdk). It serves five typed tools over
stdio so any MCP-capable agent can search and reuse the local session
history of every supported agent:

- list_sessions: newest-first summaries with provider, workspace-substring,
  and free-text filters (workspace + first/last user message), limit
  default 25 / max 100 with a total count for pagination awareness
- get_transcript: user/assistant turns, truncated to the most recent
  max_turns (default 50) so old sessions cannot flood a caller's context
- branch_session: fork a local copy via session.Branch
- convert_session: rewrite into another agent's native format via
  session.Convert
- resume_command: the exact shell command + cwd to resume, never executed

Deliberately no delete tool: destructive actions stay behind the TUI's
two-press confirmation. Branch/convert only write new files through the
existing atomic paths; originals are never touched.

Tests connect an in-memory MCP client to the real server so filtering,
end-truncation, branch, and convert are exercised through full tool
dispatch, hermetically via the provider home env overrides.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`showagent mcp` runs the MCP server on stdin/stdout until the client
disconnects or the process is interrupted; extra arguments are a usage
error. Help text documents the new subcommand and its non-destructive,
never-executes contract.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds the "Use it from inside your agent (MCP)" section: the shared-memory
pitch, claude/codex wiring examples, the tool table, and the explicit
no-delete/no-exec note. Tops the README with the mcp-name registry
annotation (io.github.aytzey/showagent).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an internal/mcpserver package implementing an MCP server exposing session history tools (list_sessions, get_transcript, branch_session, convert_session, resume_command) over stdio, wires a new showagent mcp CLI subcommand, updates go.mod dependencies, and documents MCP usage in README.md.

Changes

MCP session server

Layer / File(s) Summary
Dependency updates
go.mod
Adds github.com/modelcontextprotocol/go-sdk and related indirect dependencies.
Server construction and registration
internal/mcpserver/server.go
Constructs the MCP server, registers tool annotations, and adds a Run entrypoint starting the stdio transport.
list_sessions and get_transcript tools
internal/mcpserver/server.go
Implements discovery-based session listing with filters/limits and transcript retrieval with truncation and resolveRow session lookup.
branch_session, convert_session, resume_command tools
internal/mcpserver/server.go
Implements forking/converting sessions into new session records and returning exact resume commands without executing them.
Server test suite
internal/mcpserver/server_test.go
Adds fixture setup, an in-memory MCP client/server harness, and tests covering all tools, resolveRow, and matchesFilters.
CLI mcp subcommand
cmd/showagent/main.go, cmd/showagent/main_test.go
Adds mcp subcommand dispatch, help text, runMCP entrypoint, and tests for help output and argument rejection.
MCP documentation
README.md
Documents showagent mcp, configuration examples, and the tool list.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Agent as Claude/Codex Agent
    participant CLI as showagent CLI
    participant MCPServer as mcpserver.Server
    participant Store as Session Storage

    Agent->>CLI: showagent mcp
    CLI->>MCPServer: mcpserver.Run(ctx, version)
    MCPServer->>MCPServer: register tools (list_sessions, get_transcript, branch_session, convert_session, resume_command)
    Agent->>MCPServer: call list_sessions(filters)
    MCPServer->>Store: discover sessions
    Store-->>MCPServer: session rows
    MCPServer-->>Agent: filtered/sorted summaries + total

    Agent->>MCPServer: call get_transcript(id or "latest")
    MCPServer->>Store: resolveRow(id)
    Store-->>MCPServer: session row
    MCPServer-->>Agent: transcript turns (truncated)

    Agent->>MCPServer: call branch_session(id)
    MCPServer->>Store: resolveRow(id) + write new session file
    Store-->>MCPServer: new session id/path
    MCPServer-->>Agent: new session id + resume command
Loading

Possibly related PRs

  • aytzey/showagent#1: Both PRs modify cmd/showagent/main.go's CLI dispatcher and help output, extending the same subcommand routing structure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding an MCP server for agents to search and reuse session history across tools.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-server

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aytzey aytzey merged commit b775954 into main Jul 9, 2026
5 of 6 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/showagent/main.go (1)

326-341: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Consider handling SIGTERM as well as SIGINT
signal.NotifyContext only listens for os.Interrupt, so the MCP server won’t exit gracefully when a supervisor sends SIGTERM. Adding syscall.SIGTERM here is a small robustness win for containerized deployments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/showagent/main.go` around lines 326 - 341, runMCP currently only listens
for os.Interrupt via signal.NotifyContext, so it won’t shut down gracefully on
SIGTERM. Update the signal setup in runMCP to include syscall.SIGTERM alongside
os.Interrupt, keeping the rest of the mcpserver.Run flow unchanged so the MCP
server exits cleanly under container/supervisor shutdown.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/showagent/main.go`:
- Around line 326-341: runMCP currently only listens for os.Interrupt via
signal.NotifyContext, so it won’t shut down gracefully on SIGTERM. Update the
signal setup in runMCP to include syscall.SIGTERM alongside os.Interrupt,
keeping the rest of the mcpserver.Run flow unchanged so the MCP server exits
cleanly under container/supervisor shutdown.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94d3b0a2-009e-47d9-9d00-553a9b6efed5

📥 Commits

Reviewing files that changed from the base of the PR and between dfabdf1 and 4619c7c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • README.md
  • cmd/showagent/main.go
  • cmd/showagent/main_test.go
  • go.mod
  • internal/mcpserver/server.go
  • internal/mcpserver/server_test.go

@aytzey aytzey deleted the feat/mcp-server branch July 9, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant